package com.ruoyi.hr.controller.hr.welfare.welfarepayment;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.domain.welfare.welfarecalculationconfig.CcdBenefititem;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.welfare.welfarecalculationconfig.ICcdBenefititemService;
import com.ruoyi.hr.service.welfare.welfarepayment.WelfarePaymentHistoryService;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 福利补缴历史
 * @date 2019/1/8 15:44
 */
@Controller
@RequestMapping("/welfare/welfarePayment/welfarePaymentHistory")
public class WelfarePaymentHistoryController extends BaseController {

    @Autowired
    private WelfarePaymentHistoryService welfarePaymentHistoryService;

    @Autowired
    ICcdBenefititemService iCcdBenefititemService;

    @Autowired
    AuthorityService authorityService;

    private String prefix = "hr/welfare/welfarepayment/welfarepaymenthistory";

    @GetMapping()
    public String welfarePaymentHistory() {
        return prefix + "/welfarePaymentHistory";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> map) {
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        List<Map<String, Object>> list = welfarePaymentHistoryService.findData(map,authorityList,isAdmin);
        return getDataTable(list);
    }

    /**
     * 动态获取表头
     */
    @PostMapping("/findHeader")
    @ResponseBody
    public List<CcdBenefititem> findHeader() {
        List<CcdBenefititem> ccdBenefititems = iCcdBenefititemService.findPayBack();
        return ccdBenefititems;
    }
}

